package com.allwees.bs.module.fms.req.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.allwees.bs.core.modelbase.branch.EBranchType;
import com.allwees.bs.core.modelbase.req.QueryReq;
import com.allwees.bs.module.fms.constant.EAccountLogBsType;
import com.allwees.bs.module.fms.constant.EBalanceType;
import com.allwees.bs.module.fms.entity.BaseAccountLog;
import com.allwees.core.common.constant.EStatus;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 账务流水QueryReq
 *
 * @author yangylsky
 * @since 2020-01-03
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class AccountLogQueryReq<T extends BaseAccountLog> extends QueryReq<T> {

	/**
	 *  交易流水号
	 */
	private String no;



	/**
	 * 提现账户
	 */
	private  String bankAccountNo;


	private EBranchType branchType;

	private  Integer accountType;

	private String branchUuid;

	/**
	 * 收支类型
	 */
	private EBalanceType balanceType;

	/**
	 * 账务流水类型
	 */
	private EAccountLogBsType bsType;

	/**
	 * 提现状态
	 */
	private EAccountLogStatus status;

	/**
	 * 本方帐号
	 */
	private String accountNo;


	/**
	 * 提现时间
	 */
	private Date createdAtFrom;
	/**
	 * 提现时间
	 */
	private Date createdAtTo;

	private Date completedAtFrom;

	private Date completedAtTo;

	@Override
	protected void buildQuery(QueryWrapper<T> queryWrapper) {
		queryWrapper
				.eq(StringUtils.isNotBlank(no), "no", no)
			.eq(StringUtils.isNotBlank(branchUuid), "branch_uuid", branchUuid)
                .eq(accountType != null, "account_type", accountType)

			.eq(StringUtils.isNotBlank(accountNo), "account_no", accountNo)
			.eq(StringUtils.isNotBlank(bankAccountNo), "bank_account_no", bankAccountNo)
			.ge(createdAtFrom != null, "created_at", createdAtFrom)
			.le(createdAtTo != null, "created_at", createdAtTo)
			.ge(completedAtFrom != null, "completed_at", completedAtFrom)
			.le(completedAtTo != null, "completed_at", completedAtTo)
			.in(null != status, "status", status != null? status.entityStatus():null )
			.eq(null != branchType, "branch_type", branchType)
			.eq(null != bsType, "bs_type", bsType);
	}

	public enum EAccountLogStatus {
		AUDITING {
			@Override
			List<Integer> entityStatus() {
				return Arrays.asList(EStatus.WAIT_AUDIT.value());
			}
		},
		WITHDRAWING {
			@Override
			List<Integer> entityStatus() {
				return Arrays.asList(EStatus.AUDIT_APPROVED.value());
			}
		},
		COMPLETED {
			@Override
			List<Integer> entityStatus() {
				return Arrays.asList(
						EStatus.NORMAL.value(),
						EStatus.COMPLETED.value()
					);
			}
		},
		REJECTED {
			@Override
			List<Integer> entityStatus() {
				return Arrays.asList(EStatus.AUDIT_REJECTED.value());
			}
		},
		WITHDRAWFAILED {
			@Override
			List<Integer> entityStatus() {
				return Arrays.asList(EStatus.WITH_DRAW_FAILED.value());
			}
		};

		abstract List<Integer> entityStatus();
	}
}
